layui.use(['table','form','laydate','jquery','upload'], function(){
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    var $ = layui.$; //重点处
    var upload = layui.upload;
    //第一个实例
    table.render({
        elem: '#table_list',
        limit: 30,
        height: 'full-130',
        method: 'post',
        text: {none: '暂无相关数据'},
        url: '/logic/logic_shares/listData', //数据接口
        page: true, //开启分页
        toolbar:"#table_list_tool",

        cols: [[ //表头
            {type:'radio',width:30,fixed: 'left'},
            {field: 'code', title: '编码', width:120,align:"center",sort: true,},
            {field: 'name', title: '名称', width:120,align:"center",sort: true,},
            {field: 'stockExchange', title: '交易所', width:120,align:"center",sort: true,},
            {field: 'maxPrice', title: '上次牛市最大价格', width:160,align:"center",sort: true,
                templet(col){return "¥ "+CommonUtil.isEmptyReturn(col.maxPrice ,0);}
            },
            {field: 'currentPrice', title: '当前价格', width:120,align:"center",sort: true,
                templet(col){
                CommonUtil.isEmptyReturn()
                    return "¥ "+CommonUtil.isEmptyReturn(col.currentPrice,0);
                }
            },
            {field: 'proposalBuyPrice', title: '建议购买价格', width:130,align:"center",sort: true,
                templet(col){return "¥ "+ CommonUtil.isEmptyReturn(col.proposalBuyPrice,0);}
            },
            {field: 'buyPrice', title: '设定购买价格', width:120,align:"center",sort: true,
                templet(col){return "¥ "+CommonUtil.isEmptyReturn(col.buyPrice,0);}
            },
            {field: 'sellPrice', title: '设定销售价格', width:130,align:"center",sort: true,
                templet(col){return "¥ "+ CommonUtil.isEmptyReturn(col.sellPrice,0);}
            },
            {field: 'currentCostPrice', title: '成本价', width:120,align:"center",sort: true,
                templet(col){return "¥ "+CommonUtil.isEmptyReturn(col.currentCostPrice,0);}
            },

            {field: 'netAssets', title: '净资产', width:120,align:"center",sort: true,
                templet(col){return "¥ "+CommonUtil.isEmptyReturn(col.netAssets,0);}
            },

            {field: 'difference', title: '差额', width:120,align:"center",sort: true,
                templet(col){return "¥ "+CommonUtil.isEmptyReturn(col.difference,0);}
            },
            {field: 'differenceRatio', title: '差额比例', width:120,align:"center",sort: true,
                templet(col){return CommonUtil.isEmptyReturn(col.differenceRatio,0) +"%";}
            },


            {field: 'debtRatio', title: '负债率', width:120,align:"center",sort: true,
                templet(col){return CommonUtil.isEmptyReturn(col.debtRatio +"%",0);}
            },
            {field: 'doubleSales', title: '两倍', width:120,align:"center",sort: true,},
        ]],
        parseData: function(result){
            return CommonUtil.layuiParseData(result);
        },
    });

    //搜索初始化
    form.on('submit(search)', function(data){
        //阻止表单跳转。如果需要表单跳转，去掉这段即可。 默认返回 false
        return CommonUtil.layuiInitSearch("table_list",data);
    });

    //工具栏监听事件
    table.on('toolbar(table_list_filter)', function(obj){
        switch(obj.event){
            case 'add': CommonUtil.layuiEditPage("/logic/logic_shares/editPage","新增股票信息",700,720,obj); break;
            case 'edit': CommonUtil.layuiEditPage("/logic/logic_shares/editPage","修改股票信息",700,720,obj); break;
            case 'del': CommonUtil.layuiDeleteData("/logic/logic_shares/removed","search",obj); break;
        };
    });

    //指定允许上传的文件类型
    upload.render({
        elem: '#fileUpload'
        ,url: '/logic/logic_shares/importShares'
        ,accept: 'file' //普通文件
        ,done: function(res){
            console.log(res)
        }
    });
});
